<?php

namespace App\VO\ConvertibleCard;

use App\Entities\ConvertibleCardEntity;
use App\VO\Interfaces\IVODetail;
use Illuminate\Support\Carbon;

class VODetail implements IVODetail
{
    use CommonTrait;

    public $id = 0;
    // public $title = '';
    // public $typeName = '';
    // public $value = 0;//使用次数/面值
    // public $price = 0;//分
    // public $soldCount = 0;
    // public $statusName = '';
    // public $endSaleDate = '';
    // public $durationDays = 0;
    // public $daysBeforeExpireStr = '';
    // public $createTime = '';
    // public $operator = '';
    public $detailImage = '';
    public $bannerImage = '';

    public function __construct(array $data)
    {
        if (isset($data['cardentity']) && $data['cardentity'] instanceof ConvertibleCardEntity) {
            $cardEntity = $data['cardentity'];
            $this->assign($cardEntity);
            $this->bannerImage = $cardEntity->getBanner();
            $this->detailImage = $cardEntity->getDetailImage();
            // $this->createTime = $cardEntity->getCreatedAt();
            // if ($this->createTime instanceof Carbon) {
            //     $this->createTime = $this->createTime->toDateTimeString();
            // }
            // $this->operator = $cardEntity->getOperator();
            // $endSaleTimestamp = strtotime($cardEntity->getEndSale());
            // $time = time();
            // if ($endSaleTimestamp > $time) {
            //     $days = ceil(($endSaleTimestamp - $time) / 86400);
            //     $this->daysBeforeExpireStr = $days. '天后下架';
            // }
        }
    }
}
